import crcmod


def crc16_modbus(data):
    crc16_fun = crcmod.mkCrcFun(0x18005, rev=True, initCrc=0xFFFF, xorOut=0x0000)
    return crc16_fun(data)


data = [0x01, 0x03, 0x00, 0x03, 0x00, 0x01]
ret_crc16_modbus = 0x0A74
byte_data = bytes(data)
crc16 = crc16_modbus(byte_data)
print(f"crc16_modbus: hex(crc16), 比较结果={crc16 == ret_crc16_modbus}")
"crc16_modbus: hex(crc16), 比较结果=True"
